﻿using System.Data;
using Microsoft.VisualStudio.DebuggerVisualizers;

namespace DataReaderVisualizer
{
    public class DataReaderObjectSource : VisualizerObjectSource
    {
        private readonly IDataTableFactory dataTableFactory;

        public DataReaderObjectSource()
            : this(new DataTableFactory())
        {
        }

        private DataReaderObjectSource(IDataTableFactory dataTableFactory)
        {
            this.dataTableFactory = dataTableFactory;
        }

        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            base.GetData(dataTableFactory.Create((IDataReader)target), outgoingData);
        }
    }
}
